<?php
//CRUD functions
if (isset($_POST['action'])) {
   switch ($_POST['action']) {
      case 'Save':
         $newShiftData = array(
             "roleID" => $_POST['roleID'],
             "accName" => $_POST['accName'],
             "datestamp" => $_POST['datestamp'],
             "startTime" => $_POST['startTime'],
             "endTime" => $_POST['endTime']
         );
         $resultsAddShift = addShift(
                 $_SESSION['userName'], $_SESSION['userName'], $newShiftData);
         print_r($resultsAddShift);
         break;
   }
}
//CRUD functions
//grab the accounts
$getAccountsResult = getAccounts($_SESSION['userName'], $_SESSION['userPassHash']);
$accounts = $getAccountsResult['results'];

//grab the roles
$getRolesResult = getRoles($_SESSION['userName'], $_SESSION['userPassHash']);
$roles = $getRolesResult[1];
?>

<form action="" method="post">
   <table>
      <tr>
         <td>
            <label>Date</label>
         </td>
         <td>
            <input type="date" name="datestamp" REQUIRED />
         </td>
      </tr>
      <tr>
         <td>
            <label>Employee</label>
         </td>
         <td>
            <select name="accName">
<?php
foreach ($accounts as $account) {
   echo ("<option value=" . $account['accName']);
   echo (">" . $account['accName'] . "</option>");
}
?>
            </select>
         </td>
      </tr>
      <tr>
         <td>
            <label>Role</label>
         </td>
         <td>
            <select name="roleID">
<?php
foreach ($roles as $role) {
   echo ("<option value=" . $role['roleID']);
   echo (">" . $role['roleName'] . "</option>");
}
?>
            </select>
         </td>
      </tr>
      <tr>
         <td>
            <label>Start Time</label>
         </td>
         <td>
            <input type="time" name="startTime" REQUIRED />
         </td>
      </tr>
      <tr>
         <td>
            <label>End Time</label>
         </td>
         <td>
            <input type="time" name="endTime" />
         </td>
      </tr>
   </table>
   <input type="submit" name="action" value="Save"/>
</form>

